#ifndef _Image_h
#define _Image_h

#include "zf_common_typedef.h"
#define image_h      70
#define image_w      155
#define HEIGHT       70
#define WIDTH        155
#define USE_num	image_h*6	//定义找点的数组成员个数按理说300个点能放下，但是有些特殊情况确实难顶，多定义了一点
#define bin_jump_num	1         //跳过的点数
#define border_max	    image_w-2 //边界最大值
#define border_min	    1	      //边界最小值	


extern uint8  Longest_Left_Wite_Line[2]; //左边最长白列
extern uint8  Longest_Right_Wite_Line[2];//右边最长白列
extern uint8 start_point_l[2];//左边起点的x，y值
extern uint8 start_point_r[2];//右边起点的x，y值
extern uint16 points_l[(uint16)USE_num][2] ;//左线
extern uint16 points_r[(uint16)USE_num][2];//右线
extern uint16 dir_r[(uint16)USE_num];//用来存储右边生长方向
extern uint16 dir_l[(uint16)USE_num];//用来存储左边生长方向
extern uint16 data_stastics_l;//统计左边找到点的个数
extern uint16 data_stastics_r;//统计右边找到点的个数
extern uint8 hightest;//最高点
extern uint8 l_border[image_h];//左线数组
extern uint8 r_border[image_h];//右线数组
extern uint8 center_line[image_h];//中线数组
extern uint8 Wite_Line[image_w];          //每一行的长白列个数
extern uint8 Y_Border_Min;
extern uint8 Y_Border_Max;
extern uint8 X_Border_Max;
extern uint8 X_Border_Min;

extern uint8 L_Up_Turn_Left_Point_1[2] ;      //存储上转左拐点的坐标
extern uint16 L_Up_Turn_Left_Point_Flag_1;      //上转左拐点存在标志位，找到时置1
extern uint16 L_Up_Turn_Left_Point_Position_1;  //记录位置，即是二维数组中的第几个点

extern uint8 L_Right_Turn_Up_Point_1[2] ;
extern uint16 L_Right_Turn_Up_Point_Flag_1;
extern uint16 L_Right_Turn_Up_Point_Position_1;
extern float L_Right_Turn_Up_Point_Angle_1;

extern uint8 R_Up_Turn_Right_Point_1[2] ;
extern uint16 R_Up_Turn_Right_Point_Flag_1;
extern uint16 R_Up_Turn_Right_Point_Position_1;
extern float R_Up_Turn_Right_Point_Angle_1 ;

extern uint8 R_Left_Turn_Up_Point_1[2] ;
extern uint16 R_Left_Turn_Up_Point_Flag_1 ;
extern uint16 R_Left_Turn_Up_Point_Position_1 ;
extern float R_Left_Turn_Up_Point_Angle_1 ;

extern uint8 R_Left_Turn_Up_Point[2];
extern uint8 R_Left_Turn_Up_Point_Flag ;
extern uint8 R_Up_Turn_Right_Point[2];
extern uint8 R_Up_Turn_Right_Point_Flag ;
extern uint8 L_Right_Turn_Up_Point[2];
extern uint8 L_Right_Turn_Up_Point_Flag;
extern uint8 L_Up_Turn_Left_Point[2];
extern uint8 L_Up_Turn_Left_Point_Flag ;

extern uint8 L_Arc_Turn_Point[3][2] ;   //最多找三个就足够使用
extern uint16 L_Arc_Turn_Point_Flag ;    //找到一个就挂出标志位
extern uint8 L_Arc_Turn_Point_Num ;     //记录找到的个数

extern uint8 R_Arc_Turn_Point[3][2] ;
extern uint8 R_Arc_Turn_Point_Flag ;
extern uint8 R_Arc_Turn_Point_Num ;

extern uint8 R_Border_Point_Num;        //记录位于左侧边界点个数
extern uint8 R_UP_Border_Point_Num;     ////记录位于顶部黑框上的边界点个数
extern uint8 L_Border_Point_Num;        //记录左侧边界点个数
extern uint8 L_UP_Border_Point_Num;     //记录位于顶部黑框上的边界点个数

extern uint8 Relative_Border_Point_Num;        //存储对位边界行的个数

extern uint8_t Left_Lose_One_Point;
extern uint8_t Right_Lose_One_Point;

extern int Left_Vpoint;
extern uint8_t Left_V[2];
extern int Right_Vpoint;
extern uint8_t Right_V[2];

extern int Left_Apoint;
extern uint8_t Left_A[2];
extern int Right_Apoint;
extern uint8_t Right_A[2];

extern int Right_AApoint;
extern uint8_t Right_AA[2];

extern int Left_AApoint;
extern uint8_t Left_AA[2];

extern int8 Row_Difference[20];
extern uint8 Max_Row_Dif_Line_Num;     //当某一行左侧边线点位于左侧边界上，右侧边线点位于右侧边线上，与对位边界行同理，可以记录下来

// extern int Whith[image_h];//赛道宽度
extern uint8_t Zhi_Dao_KuanDu[image_h];
extern float Left_S;//左边线标准差
extern float Right_S;//右边线标准差
extern float Left_Slope;//斜率
extern float Left_Intercept;//截距
extern float Right_Slope;//斜率
extern float Right_Intercept;//截距

extern int LianXu_Left;//连续性检验
extern int LianXu_Right;//连续性检验

extern int Left_Up_Point;
extern int Left_Down_Point;
extern int Right_Up_Point;
extern int Right_Down_Point;

extern int ShiZi_Flag2;//十字标志位
extern int BanMa_Flag;//斑马线标志位
extern int WanDao_Flag;
extern int ZhiDao_Flag;
extern int HuanDao_Flag;
extern int BiZhang_Flag;
extern int PoDao_Flag;

extern int Huandao_Key;
extern int Shizi_Key;
extern int Zhidao_Key;
extern int Banma_Key;
extern int Podao_Key;
extern int BiZhang_Key;
extern int WanDao_Key;

extern int BiZhang_Stace;

extern float Left_Slope_A;
extern float Left_Slope_B;
extern float Left_Slope_All;
extern float Right_Slope_A;
extern float Right_Slope_B;
extern float Right_Slope_All;

extern int Left_ZhiDao_Flag;
extern int Right_ZhiDao_Flag;

extern int Right_Center;
extern int Left_Center;

extern int HuanDao_Stas;//环岛状态机

extern float Mid_Error;//最终输出误差

extern int Black_Flag;

extern int Left_Monotonicity;
extern int Right_Monotonicity;

extern int a_Flag;

extern int Scan_Mun2[80];

extern uint8_t hightest_Average;

extern int BanMaXianTime;
extern int Look_Start_Line;

// extern int First_Point_Huandao1;
extern uint16 cha1,cha2,cha3;
extern int R_First_Point_Huandao;

extern float Bizhang_Num;

extern int Auto_Speed_Flag;//自动控制速度标志位
// extern int White_Huandao;
// extern int Baidain_Huandao;

extern int Bizhang_P;

int my_abs(int value);
int16 limit_a_b(int16 x, int a, int b);
int16 limit1(int16 x, int16 y);
void image_draw_rectan(uint8(*image)[image_w]);
uint8 get_start_point(uint8 start_row);
void search_l_r(uint16 break_flag, uint8(*image)[image_w], uint16 *l_stastic, uint16 *r_stastic, uint8 l_start_x, uint8 l_start_y, uint8 r_start_x, uint8 r_start_y, uint8*hightest);
void get_left(uint16 total_L);
void get_right(uint16 total_R);
void Image_Ses(void);

#endif